<div class="profile-page">
  <section class="cinema">
    <div class="container">
      <span class="user-avatar">
        <%= img_tag avatar_url(@user), class: "avatar" %>
      </span>

      <h1>
        <%= if name = display_name(@user) do %>
          <%= name %> (<%= username(@user) %>)
        <% else %>
          <%= username(@user) %>
        <% end %>

        <small>Joined on <%= joined_at(@user) %></small>
      </h1>

      <%= if @show_edit_link do %>
        <p class="actions">
          <%= link "Edit profile", to: Routes.user_path(@conn, :edit) %>
        </p>
      <% end %>
    </div>
  </section>

  <div class="container">
    <%= if @user_is_self do %>
      <%= if @asciicast_count > 0 do %>
        <h2>You have recorded <%= pluralize(@asciicast_count, "asciicast") %></h2>
      <% else %>
        <h2>Record your first asciicast</h2>
      <% end %>
    <% else %>
      <%= if @asciicast_count > 0 do %>
        <h2><%= pluralize(@asciicast_count, "public asciicast") %> by <%= username(@user) %></h2>
      <% else %>
        <h2><%= username(@user) %> has no public asciicasts</h2>
      <% end %>
    <% end %>

    <div class="row asciicast-list">
      <div class="col-md-12">
        <%= case {@asciicast_count, @user_is_self} do %>
        <% {0, true} -> %>
          <p>
            Make sure you have asciinema recorder <%= link "installed", to: Routes.doc_path(@conn, :show, :installation) %>.
          </p>

          <p>
            To start recording run the following command in your terminal:
          </p>

          <pre><code>$ asciinema rec</code></pre>

          <p>
            When you're ready to finish just exit the shell,
            either by typing <code>exit</code> or hitting <kbd>C-d</kbd>.
          </p>

          <p>
            If you have already recorded an asciicast but you don't see it
            here then associate it with your account by running
            <code>asciinema auth</code> in your terminal.
          </p>

        <% {0, false} -> %>

        <% _ -> %>
          <%= for asciicasts <- Enum.chunk_every(@page, 3, 3) do %>
            <div class="row">
              <%= for asciicast <- asciicasts do %>
                <div class="col-md-4">
                  <%= render AsciinemaWeb.AsciicastView, "_card.html", conn: @conn, asciicast: asciicast %>
                </div>
              <% end %>
            </div>
          <% end %>
        <% end %>
      </div>
    </div>

    <%= if @page.total_pages > 1 do %>
      <div class="row">
        <div class="col">
          <%= pagination_links @page %>
        </div>
      </div>
    <% end %>
  </div>
</div>
